import pickle

import matplotlib.pyplot as plt

# Define parameters
GRID_SIZE = (160, 160)
NUM_HEIGHT_LAYERS = 8
NUM_FRAMES = 16
Z_MIN = -1
Z_MAX = 10

def plot_frame(frame, frame_idx, x_range=(-40, 40), y_range=(0, 80)):
    if not frame:
        return
    
    x = frame.get('x', [])
    y = frame.get('y', [])
    z = frame.get('z', [])
    
    plt.figure(figsize=(8, 6))
    scatter = plt.scatter(x, y, c=z, cmap='viridis', s=1)
    plt.colorbar(scatter, label='Z 值')
    plt.xlabel('X')
    plt.ylabel('Y')
    plt.title(f'Frame {frame_idx} 的散点图')
    
    plt.xlim(x_range)
    plt.ylim(y_range)
    
    plt.gca().set_aspect('equal')
    
    plt.show()


def main():
    file_path = "./workspace/image/SAR/input/pointCloud_4485.pkl"
    
    with open(file_path, 'rb') as f:
        data = pickle.load(f).get('data', [])
    
    for idx, frame in enumerate(data):
        plot_frame(frame, idx)
                    

if __name__ == "__main__":
    main()
